extends layout

block content
  .container-fluid
    h1 #{__('Coinbase Transactions')}
    - var peers = {1: 'A', 2: 'B', 3: 'C'}
    each peer, chain in peers
      h3 #{__('Peer')} #{peer}
      .row.row-horizon
        - var blocks = []
        - blocks.push({block: 1, chain: chain, nonce: 16651, coinbasevalue: '100.00', coinbaseto: 'Anders', txs: [], previous: '0000000000000000000000000000000000000000000000000000000000000000'})
        - blocks.push({block: 2, chain: chain, nonce: 215458, coinbasevalue: '100.00', coinbaseto: 'Anders', txs: [{value: '10.00', from: 'Anders', to: 'Sophia'},{value: '20.00', from: 'Anders', to: 'Lucas'},{value: '15.00', from: 'Anders', to: 'Emily'},{value: '15.00', from: 'Anders', to: 'Madison'}], previous: '0000438d7625b86a6f366545b1929975a0d3ff1f8847e56cc587cadddb0ab781'})
        - blocks.push({block: 3, chain: chain, nonce: 146, coinbasevalue: '100.00', coinbaseto: 'Anders', txs: [{value: '10.00', from: 'Emily', to: 'Jackson'},{value: '5.00', from: 'Madison', to: 'Jackson'},{value: '20.00', from: 'Lucas', to: 'Grace'}], previous: '0000baeab68c2a60f9a6fa56355438d97c672a15494fcea617064d9314f9ff63'})
        - blocks.push({block: 4, chain: chain, nonce: 18292, coinbasevalue: '100.00', coinbaseto: 'Anders', txs: [{value: '15.00', from: 'Jackson', to: 'Ryan'},{value: '5.00', from: 'Emily', to: 'Madison'},{value: '8.00', from: 'Sophia', to: 'Jackson'}], previous: '0000df1d632b734f5a5fc126a0f0e8894fb4c8314ba7086b62980559af6771b9'})
        - blocks.push({block: 5, chain: chain, nonce: 108899, coinbasevalue: '100.00', coinbaseto: 'Sophia', txs: [{value: '2.00', from: 'Jackson', to: 'Alexander'},{value: '6.00', from: 'Ryan', to: 'Carter'},{value: '4.00', from: 'Ryan', to: 'Riley'},{value: '9.95', from: 'Grace', to: 'Katherine'}], previous: '0000c694336f88129f3685bd3ba5d67c445dfd8d18bd22f5d87301dd560eb30e'})
        each block in blocks
          .col-xs-7
            include includes/coinbaseblock

  script.
    $(function() {
      setup(1, 1);
      setup(2, 1);
      setup(3, 1);
      setup(4, 1);
      setup(5, 1);

      setup(1, 2);
      setup(2, 2);
      setup(3, 2);
      setup(4, 2);
      setup(5, 2);

      setup(1, 3);
      setup(2, 3);
      setup(3, 3);
      setup(4, 3);
      setup(5, 3);
    });

    function getText(block, chain) {
      var s = $('#block'+block+'chain'+chain+'number').val() +
              $('#block'+block+'chain'+chain+'nonce').val() +
              $('#block'+block+'chain'+chain+'coinbasevalue').val() +
              $('#block'+block+'chain'+chain+'coinbaseto').val();

      for (var x=0; $('#block'+block+'chain'+chain+'tx'+x+'value').length > 0; x++) {
        s = s + $('#block'+block+'chain'+chain+'tx'+x+'value').val() +
                $('#block'+block+'chain'+chain+'tx'+x+'from').val() +
                $('#block'+block+'chain'+chain+'tx'+x+'to').val();
      }
      s = s + $('#block'+block+'chain'+chain+'previous').val();
      return s;
    }

    function setup(block, chain) {
      updateHash(block, chain);
      $('#block'+block+'chain'+chain+'number').bind('input propertychange', function() { updateChain(block, chain); });
      $('#block'+block+'chain'+chain+'nonce').bind('input propertychange', function() { updateChain(block, chain); });
      $('#block'+block+'chain'+chain+'coinbasevalue').bind('input propertychange', function() { updateChain(block, chain); });
      $('#block'+block+'chain'+chain+'coinbaseto').bind('input propertychange', function() { updateChain(block, chain); });
      for (var x=0; $('#block'+block+'chain'+chain+'tx'+x+'value').length > 0; x++) {
        $('#block'+block+'chain'+chain+'tx'+x+'value').bind('input propertychange', function() { updateChain(block, chain); });
        $('#block'+block+'chain'+chain+'tx'+x+'from').bind('input propertychange', function() { updateChain(block, chain); });
        $('#block'+block+'chain'+chain+'tx'+x+'to').bind('input propertychange', function() { updateChain(block, chain); });
      }
      $('#block'+block+'chain'+chain+'mineButton').click(function(e) {
          e.preventDefault();
          var l = Ladda.create(this);
          l.start();
          setTimeout(function() {
              mine(block, chain, true);
              l.stop();
            }, 250); // give UI time to update
        });
    }
